package autumn.recruit;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

/**
 * @author dangqi
 * @date 2021/8/2 18:51
 */
public class Shopee {
    public static void main(String[] args) {
        String s = "<people><name>shopee</name></people><age></age>";
//        String path = "people.name";
//        System.out.println(GetXMLValue(s, path));
        String regex = ">?</?|>";
        System.out.println(Arrays.toString(s.substring(1).split(regex)));

    }

    public static int depart(int n, int k, int now){
        if(k==1) return 1;
        int count = 0;
        for(int i = now; i <= n/k; i++){
            count += depart(n-i, k -1, i);
        }
        return count;
    }
    public static String GetXMLValue2(String inxml, String path) {
        String[] paths = path.split("\\.");
        String regex = ">?</?|>";
        String[] split = inxml.substring(1).split(regex);
        Deque<String> stack = new LinkedList<>();



        return inxml;
    }
    public static String GetXMLValue(String inxml, String path) {
        String[] paths = path.split("\\.");
        for(int i = 0; i < paths.length; i++){
            if(!inxml.contains(paths[i])) return "";
            String regex = String.format("<%s>|</%s>", paths[i], paths[i]);
            String[] split = inxml.split(regex);
            System.out.println(Arrays.toString(split));
            if(split[0].contains("<")) return "";
            if(split.length<=1) {
                return i == paths.length - 1 ? split[0] : "";
            }else {
                inxml = split[1];
            }
        }
        return inxml;
    }
    public static int findBalancedIndex(int[] inputArray) {
        int len = inputArray.length;
        int[] pre = new int[inputArray.length];
        int[] hou = new int[inputArray.length];
        pre[0] = hou[len-1] = 0;
        for (int i = 1; i < len ; i++){
            int j = len - 1 - i;
            pre[i] = pre[i-1] + inputArray[i-1];
            hou[j] = hou[j+1] + inputArray[j+1];
        }
        for(int i = 0; i < len; i++){
            if(pre[i] == hou[i]) return i;
        }
        return -1;
    }
}
